home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Diet Coke < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.5 KB  |  139 lines  |  [TEXT/ToyS]

  1. property gfiDestFolder : ""
  2.  
  3. property gfiRecursePath : "" --"Contains path down to where the files are from where they started
  4. property kfiRecurseDepth : 32
  5. property kfiOnlyFiles : true
  6. property kfiOnlyFolders : false
  7. property kfiDoInvisibles : false
  8.  
  9.  
  10.  
  11. on open fsObj
  12.     repeat with x in fsObj
  13.         fiRecurse(fiAliasToCmd(x), kfiRecurseDepth)
  14.     end repeat
  15. end open
  16.  
  17.  
  18. on fiOpenAgt(fileCmd)
  19.     fiIsPowered(fcAlias of fileCmd, true)
  20. end fiOpenAgt
  21.  
  22.  
  23.  
  24. on fiRecurse(fileCmd, levels)
  25.     -- Walks a folder, sending all files to "open", levels is the maximum depth to go
  26.     -- The global property gfiRecursePath contains the folders up to where we are
  27.     --
  28.     -- 27.06.97 Take fileCmd as parm, support files & folders, correct bug in missing the parent folder of a file when kfiOnlyFiles is FALSE
  29.     if (isFolder of fileCmd) then
  30.         if (not kfiOnlyFiles) then fiOpenAgt(fileCmd)
  31.         
  32.         -- Save our taken route and add this folder onto the current route
  33.         set savePath to gfiRecursePath
  34.         set gfiRecursePath to savePath & (fcName of fileCmd) & ":"
  35.         
  36.         -- Get parent path of subsequent objects and a list of them        
  37.         set fsDad to (fcAlias of fileCmd) as string
  38.         set folderContents to list folder (fcAlias of fileCmd)
  39.         
  40.         -- Walk the objects
  41.         repeat with objName in folderContents
  42.             set thing to fiAliasToCmd((fsDad & objName) as alias)
  43.             -- Process only if visible?
  44.             if (kfiDoInvisibles or isVis of thing) then
  45.                 if (isFolder of thing) then
  46.                     -- Further recursion?
  47.                     if (kfiRecurseDepth > 0) then
  48.                         if (levels is 0) then
  49.                             dgMsg(kerTooDeep)
  50.                         else
  51.                             fiRecurse(thing, levels - 1)
  52.                         end if
  53.                     end if
  54.                 else if (not kfiOnlyFolders) then
  55.                     fiOpenAgt(thing)
  56.                 end if
  57.             end if
  58.         end repeat
  59.         
  60.         set gfiRecursePath to savePath
  61.     else if not kfiOnlyFolders then
  62.         fiOpenAgt(fileCmd)
  63.     end if
  64. end fiRecurse
  65.  
  66.  
  67.  
  68. on fiAliasToCmd(fsObj)
  69.     -- This stores an alias and its info in one record
  70.     set fsName to fsObj as string
  71.     set isFold to (last character of fsName is ":")
  72.     if (isFold) then set fsName to text from character 1 to -2 of fsName -- chop off colon
  73.     
  74.     -- Break on path breaks
  75.     set saveDelims to the text item delimiters
  76.     set the text item delimiters to ":"
  77.     
  78.     -- Break it down…
  79.     set objName to the last text item of fsName
  80.     set objVolume to the first text item of fsName
  81.     set objFolder to the text from character 1 to ((length of fsName) - (length of objName)) of fsName
  82.     
  83.     -- Restore delimiters
  84.     set the text item delimiters to saveDelims
  85.     
  86.     -- new FileCmd
  87.     script fileCmd
  88.         property isVis : true -- boolean
  89.         property isFolder : isFold -- boolean
  90.         property fcAlias : fsObj -- alias
  91.         property fcVolume : objVolume -- string
  92.         property fcParent : objFolder -- string
  93.         property fcName : objName -- string
  94.     end script
  95.     
  96.     return fileCmd
  97. end fiAliasToCmd
  98.  
  99.  
  100.  
  101. property kfiPoweredHeader : "Joy!peffpwpc"
  102.  
  103. on fiIsPowered(aliasObj, slimDown)
  104.     set isPowered to false
  105.     set headLen to (length of kfiPoweredHeader)
  106.     
  107.     set fInfo to basic info for aliasObj
  108.     
  109.     if (data fork length of fInfo ≥ headLen) then
  110.         set forkRef to open fork from aliasObj write access slimDown
  111.         
  112.         if (forkRef > 0) then
  113.             set headerText to read data from forkRef ¬
  114.                 using buffer size headLen with «class text»
  115.             
  116.             set isPowered to (headerText = kfiPoweredHeader)
  117.             
  118.             -- Kill data fork if requested and it's PowerPC code
  119.             if (isPowered and slimDown) then
  120.                 set err to size fork forkRef given «class len »:0
  121.                 if (err is not 0) then beep
  122.             end if
  123.             
  124.             close fork forkRef
  125.         else
  126.             beep
  127.         end if
  128.     end if
  129.     
  130.     return isPowered
  131. end fiIsPowered
  132.  
  133.  
  134.  
  135.  
  136. on dgMsg(msgStr)
  137.     display dialog msgStr buttons {"Damn!"} default button 1
  138. end dgMsg
  139.